package com.ami.kvm.jviewer.gui;

import java.awt.event.KeyEvent;
import java.util.HashMap;

import com.ami.iusb.FloppyRedir;
import com.ami.kvm.jviewer.Debug;
import com.ami.kvm.jviewer.JViewer;
import com.ami.kvm.jviewer.hid.KeyProcessor;
import com.ami.kvm.jviewer.hid.USBKeyProcessorAZERTY;
import com.ami.kvm.jviewer.hid.USBKeyProcessorEnglish;
import com.ami.kvm.jviewer.hid.USBKeyProcessorJapaneseHost;
import com.ami.kvm.jviewer.hid.USBKeyProcessorQWERTY;
import com.ami.kvm.jviewer.hid.USBKeyProcessorQWERTZ;
import com.ami.kvm.jviewer.hid.USBKeyProcessorTurkishF;
import com.ami.kvm.jviewer.hid.USBKeyboardRep;
import com.ami.kvm.jviewer.kvmpkts.KVMClient;

public class AutoKeyboardLayout {
	public static final int KBD_TYPE_AUTO = 0;
	public static final int KBD_TYPE_FRENCH = 1036;
	public static final int KBD_TYPE_SPANISH = 1034;
	public static final int KBD_TYPE_GERMAN = 1031;
	public static final int KBD_TYPE_ENGLISH_US = 1033;
	public static final int KBD_TYPE_JAPANESE = 1041;
	public static final int KBD_TYPE_ENGLISH_UK = 2057;
	public static final int KBD_TYPE_GERMAN_SWISS = 2055;
	public static final int KBD_TYPE_FRENCH_BELGIUM = 2060;
	public static final int KBD_TYPE_ITALIAN = 1040;
	public static final int KBD_TYPE_DANISH = 1030;
	public static final int KBD_TYPE_FINNISH = 1035;
	public static final int KBD_TYPE_NORWEGIAN = 1044;
	public static final int KBD_TYPE_PORTUGUESE = 2070;
	public static final int KBD_TYPE_SWEDISH = 1053;
	public static final int KBD_TYPE_DUTCH_NL = 1043;
	public static final int KBD_TYPE_DUTCH_BE = 2067;
	public static final int KBD_TYPE_TURKISH_F = 66591;
	public static final int KBD_TYPE_TURKISH_Q = 1055;
	private KeyProcessor m_keyprocessor = null;
	private int keyboardType;
	public static boolean DEAD_FLAG = false;
	public static boolean SHIFT_FLAG = false;
	public static int SHIFT_KEY_POSITION = 0;
	public static boolean ALT_GR_FLAG = false;
	public static boolean PLUS_FLAG = false;
	public static boolean JAPANESE_FLAG = false;
	public HashMap<Integer, Integer> French_linuxMap;
	public HashMap<Integer, Integer> French_WinMap;
	public HashMap<Integer, Integer> French_Alt_gr_linuxMap;
	public HashMap<Integer, Integer> Spanish_Map;
	public HashMap<Integer, Integer> Spanish_Alt_gr_linuxMap;
	public HashMap<Integer, Integer> German_Map;
	public HashMap<Integer, Integer> German_Map_Alt_gr_linuxMap;
	public HashMap<Integer, Integer> German_Swiss_Map;
	public HashMap<Integer, Integer> French_Belgium_Map;
//	private byte[] bdata;
	private int hostKeyboardType = 0;

	public AutoKeyboardLayout() {
		get_keybd_type();
		getHostKeyboardType();
		ongetKeyprocessor();
		JViewerApp.getInstance().getM_USBKeyRep().setM_USBKeyProcessor(ongetKeyprocessor());
		this.French_linuxMap = new HashMap<Integer, Integer>();
		this.French_Alt_gr_linuxMap = new HashMap<Integer, Integer>();
		this.French_WinMap = new HashMap<Integer, Integer>();
		this.Spanish_Map = new HashMap<Integer, Integer>();
		this.Spanish_Alt_gr_linuxMap = new HashMap<Integer, Integer>();
		this.German_Map = new HashMap<Integer, Integer>();
		this.German_Map_Alt_gr_linuxMap = new HashMap<Integer, Integer>();
		this.German_Swiss_Map = new HashMap<Integer, Integer>();
		this.French_Belgium_Map = new HashMap<Integer, Integer>();
		this.French_WinMap.put(Integer.valueOf(178), Integer.valueOf(192));
		this.French_WinMap.put(Integer.valueOf(249), Integer.valueOf(222));
		this.French_WinMap.put(Integer.valueOf(37), Integer.valueOf(222));
		this.French_linuxMap.put(Integer.valueOf(339), Integer.valueOf(192));
		this.French_linuxMap.put(Integer.valueOf(233), Integer.valueOf(50));
		this.French_linuxMap.put(Integer.valueOf(50), Integer.valueOf(50));
		this.French_linuxMap.put(Integer.valueOf(34), Integer.valueOf(51));
		this.French_linuxMap.put(Integer.valueOf(51), Integer.valueOf(51));
		this.French_linuxMap.put(Integer.valueOf(232), Integer.valueOf(55));
		this.French_linuxMap.put(Integer.valueOf(55), Integer.valueOf(55));
		this.French_linuxMap.put(Integer.valueOf(231), Integer.valueOf(57));
		this.French_linuxMap.put(Integer.valueOf(57), Integer.valueOf(57));
		this.French_linuxMap.put(Integer.valueOf(224), Integer.valueOf(48));
		this.French_linuxMap.put(Integer.valueOf(48), Integer.valueOf(48));
		this.French_linuxMap.put(Integer.valueOf(249), Integer.valueOf(52));
		this.French_linuxMap.put(Integer.valueOf(37), Integer.valueOf(52));
		this.French_Alt_gr_linuxMap.put(Integer.valueOf(38), Integer.valueOf(49));
		this.French_Alt_gr_linuxMap.put(Integer.valueOf(126), Integer.valueOf(50));
		this.French_Alt_gr_linuxMap.put(Integer.valueOf(35), Integer.valueOf(51));
		this.French_Alt_gr_linuxMap.put(Integer.valueOf(123), Integer.valueOf(52));
		this.French_Alt_gr_linuxMap.put(Integer.valueOf(91), Integer.valueOf(53));
		this.French_Alt_gr_linuxMap.put(Integer.valueOf(124), Integer.valueOf(54));
		this.French_Alt_gr_linuxMap.put(Integer.valueOf(96), Integer.valueOf(55));
		this.French_Alt_gr_linuxMap.put(Integer.valueOf(92), Integer.valueOf(56));
		this.French_Alt_gr_linuxMap.put(Integer.valueOf(94), Integer.valueOf(57));
		this.French_Alt_gr_linuxMap.put(Integer.valueOf(64), Integer.valueOf(48));
		this.French_Alt_gr_linuxMap.put(Integer.valueOf(93), Integer.valueOf(522));
		this.French_Alt_gr_linuxMap.put(Integer.valueOf(125), Integer.valueOf(61));
		this.French_Alt_gr_linuxMap.put(Integer.valueOf(164), Integer.valueOf(515));
		this.French_Alt_gr_linuxMap.put(Integer.valueOf(8364), Integer.valueOf(69));
		this.Spanish_Map.put(Integer.valueOf(170), Integer.valueOf(192));
		this.Spanish_Map.put(Integer.valueOf(186), Integer.valueOf(192));
		this.Spanish_Map.put(Integer.valueOf(92), Integer.valueOf(192));
		this.Spanish_Map.put(Integer.valueOf(231), Integer.valueOf(92));
		this.Spanish_Map.put(Integer.valueOf(199), Integer.valueOf(92));
		this.Spanish_Map.put(Integer.valueOf(125), Integer.valueOf(92));
		this.Spanish_Map.put(Integer.valueOf(241), Integer.valueOf(59));
		this.Spanish_Map.put(Integer.valueOf(209), Integer.valueOf(59));
		this.Spanish_Alt_gr_linuxMap.put(Integer.valueOf(92), Integer.valueOf(192));
		this.Spanish_Alt_gr_linuxMap.put(Integer.valueOf(124), Integer.valueOf(49));
		this.Spanish_Alt_gr_linuxMap.put(Integer.valueOf(64), Integer.valueOf(50));
		this.Spanish_Alt_gr_linuxMap.put(Integer.valueOf(35), Integer.valueOf(51));
		this.Spanish_Alt_gr_linuxMap.put(Integer.valueOf(126), Integer.valueOf(52));
		this.Spanish_Alt_gr_linuxMap.put(Integer.valueOf(189), Integer.valueOf(53));
		this.Spanish_Alt_gr_linuxMap.put(Integer.valueOf(172), Integer.valueOf(54));
		this.Spanish_Alt_gr_linuxMap.put(Integer.valueOf(93), Integer.valueOf(93));
		this.Spanish_Alt_gr_linuxMap.put(Integer.valueOf(123), Integer.valueOf(129));
		this.Spanish_Alt_gr_linuxMap.put(Integer.valueOf(91), Integer.valueOf(91));
		this.Spanish_Alt_gr_linuxMap.put(Integer.valueOf(8364), Integer.valueOf(53));
		this.Spanish_Alt_gr_linuxMap.put(Integer.valueOf(125), Integer.valueOf(92));
		this.German_Map.put(Integer.valueOf(223), Integer.valueOf(45));
		this.German_Map.put(Integer.valueOf(63), Integer.valueOf(45));
		this.German_Map.put(Integer.valueOf(92), Integer.valueOf(47));
		this.German_Map.put(Integer.valueOf(252), Integer.valueOf(91));
		this.German_Map.put(Integer.valueOf(220), Integer.valueOf(91));
		this.German_Map.put(Integer.valueOf(246), Integer.valueOf(59));
		this.German_Map.put(Integer.valueOf(214), Integer.valueOf(59));
		this.German_Map.put(Integer.valueOf(228), Integer.valueOf(222));
		this.German_Map.put(Integer.valueOf(196), Integer.valueOf(222));
		this.German_Map.put(Integer.valueOf(130), Integer.valueOf(192));
		this.German_Map_Alt_gr_linuxMap.put(Integer.valueOf(178), Integer.valueOf(50));
		this.German_Map_Alt_gr_linuxMap.put(Integer.valueOf(179), Integer.valueOf(51));
		this.German_Map_Alt_gr_linuxMap.put(Integer.valueOf(123), Integer.valueOf(55));
		this.German_Map_Alt_gr_linuxMap.put(Integer.valueOf(91), Integer.valueOf(56));
		this.German_Map_Alt_gr_linuxMap.put(Integer.valueOf(93), Integer.valueOf(57));
		this.German_Map_Alt_gr_linuxMap.put(Integer.valueOf(125), Integer.valueOf(48));
		this.German_Map_Alt_gr_linuxMap.put(Integer.valueOf(126), Integer.valueOf(521));
		this.German_Map_Alt_gr_linuxMap.put(Integer.valueOf(181), Integer.valueOf(77));
		this.German_Map_Alt_gr_linuxMap.put(Integer.valueOf(64), Integer.valueOf(81));
		this.German_Map_Alt_gr_linuxMap.put(Integer.valueOf(8364), Integer.valueOf(69));
		this.German_Map_Alt_gr_linuxMap.put(Integer.valueOf(92), Integer.valueOf(47));
		this.German_Map_Alt_gr_linuxMap.put(Integer.valueOf(124), Integer.valueOf(153));
		this.German_Swiss_Map.put(Integer.valueOf(167), Integer.valueOf(192));
		this.German_Swiss_Map.put(Integer.valueOf(176), Integer.valueOf(192));
		this.German_Swiss_Map.put(Integer.valueOf(39), Integer.valueOf(45));
		this.German_Swiss_Map.put(Integer.valueOf(63), Integer.valueOf(45));
		this.German_Swiss_Map.put(Integer.valueOf(252), Integer.valueOf(91));
		this.German_Swiss_Map.put(Integer.valueOf(232), Integer.valueOf(91));
		this.German_Swiss_Map.put(Integer.valueOf(246), Integer.valueOf(59));
		this.German_Swiss_Map.put(Integer.valueOf(233), Integer.valueOf(59));
		this.German_Swiss_Map.put(Integer.valueOf(228), Integer.valueOf(222));
		this.German_Swiss_Map.put(Integer.valueOf(224), Integer.valueOf(222));
		this.German_Swiss_Map.put(Integer.valueOf(45), Integer.valueOf(47));
		this.German_Swiss_Map.put(Integer.valueOf(95), Integer.valueOf(47));

		this.French_Belgium_Map.put(Integer.valueOf(178), Integer.valueOf(192));
		this.French_Belgium_Map.put(Integer.valueOf(179), Integer.valueOf(192));
		this.French_Belgium_Map.put(Integer.valueOf(249), Integer.valueOf(222));
		this.French_Belgium_Map.put(Integer.valueOf(37), Integer.valueOf(222));
		this.French_Belgium_Map.put(Integer.valueOf(181), Integer.valueOf(92));
		this.French_Belgium_Map.put(Integer.valueOf(163), Integer.valueOf(92));
	}

	private void get_keybd_type() {
		String str1 = null;
		FloppyRedir localFloppyRedir = new FloppyRedir(true);
		str1 = localFloppyRedir.ReadKeybdType();
		Debug.out.println("Keybdtype" + str1);
		String str2 = System.getProperty("os.name");
		Debug.out.println("Os_name" + str2);
		if (str2.equalsIgnoreCase("Linux")) {
			if (str1.equalsIgnoreCase("US")) {
				this.keyboardType = 1033;
			} else if (str1.equalsIgnoreCase("FR")) {
				this.keyboardType = 1036;
			} else if (str1.equalsIgnoreCase("DE")) {
				this.keyboardType = 1031;
			} else if (str1.equalsIgnoreCase("ES")) {
				this.keyboardType = 1034;
			} else if (str1.equalsIgnoreCase("JP")) {
				this.keyboardType = 1041;
			} else if (str1.equalsIgnoreCase("GB")) {
				this.keyboardType = 2057;
			} else if (str1.equalsIgnoreCase("DE-CH")) {
				this.keyboardType = 2055;
			} else if (str1.equalsIgnoreCase("FR-BE")) {
				this.keyboardType = 2060;
			} else if (str1.equalsIgnoreCase("IT")) {
				this.keyboardType = 1040;
			} else if (str1.equalsIgnoreCase("DA")) {
				this.keyboardType = 1030;
			} else if (str1.equalsIgnoreCase("FI")) {
				this.keyboardType = 1035;
			} else if (str1.equalsIgnoreCase("NO")) {
				this.keyboardType = 1044;
			} else if (str1.equalsIgnoreCase("PT")) {
				this.keyboardType = 2070;
			} else if (str1.equalsIgnoreCase("SV")) {
				this.keyboardType = 1053;
			} else if (str1.equalsIgnoreCase("NL-NL")) {
				this.keyboardType = 1043;
			} else if (str1.equalsIgnoreCase("NL-BE")) {
				this.keyboardType = 2067;
			} else if (str1.equalsIgnoreCase("TR_F")) {
				this.keyboardType = 66591;
			} else if (str1.equalsIgnoreCase("TR_Q")) {
				this.keyboardType = 1055;
			} else
				this.keyboardType = 1033;
		} else {
			try {
				str1 = str1.substring(str1.length() - 5, str1.length());
				this.keyboardType = Integer.parseInt(str1, 16);
				Debug.out.println("JViewerView.KBD_TYPE" + this.keyboardType);
			} catch (Exception localException) {
				Debug.out.println("Unknown Language");
				Debug.out.println(localException);
			}
		}
	}

	private void getHostKeyboardType() {
		String str = JViewer.getKeyboardLayout();
		if (str.equalsIgnoreCase("US")) {
			this.hostKeyboardType = 1033;
		} else if (str.equalsIgnoreCase("FR")) {
			this.hostKeyboardType = 1036;
		} else if (str.equalsIgnoreCase("DE")) {
			this.hostKeyboardType = 1031;
		} else if (str.equalsIgnoreCase("ES")) {
			this.hostKeyboardType = 1034;
		} else if (str.equalsIgnoreCase("JP")) {
			this.hostKeyboardType = 1041;
		} else if (str.equalsIgnoreCase("GB")) {
			this.hostKeyboardType = 2057;
		} else if (str.equalsIgnoreCase("DE-CH")) {
			this.hostKeyboardType = 2055;
		} else if (str.equalsIgnoreCase("FR-BE")) {
			this.hostKeyboardType = 2060;
		} else if (str.equalsIgnoreCase("IT")) {
			this.hostKeyboardType = 1040;
		} else if (str.equalsIgnoreCase("DA")) {
			this.hostKeyboardType = 1030;
		} else if (str.equalsIgnoreCase("FI")) {
			this.hostKeyboardType = 1035;
		} else if (str.equalsIgnoreCase("NO")) {
			this.hostKeyboardType = 1044;
		} else if (str.equalsIgnoreCase("PT")) {
			this.hostKeyboardType = 2070;
		} else if (str.equalsIgnoreCase("SV")) {
			this.hostKeyboardType = 1053;
		} else if (str.equalsIgnoreCase("NL-NL")) {
			this.hostKeyboardType = 1043;
		} else if (str.equalsIgnoreCase("NL-BE")) {
			this.hostKeyboardType = 2067;
		} else if (str.equalsIgnoreCase("TR_F")) {
			this.hostKeyboardType = 66591;
		} else if (str.equalsIgnoreCase("TR_Q")) {
			this.hostKeyboardType = 1055;
		} else {
			this.hostKeyboardType = 0;
		}
	}

	public int getKeyboardType() {
		get_keybd_type();
		return this.keyboardType;
	}

	public void setKeyboardType(int paramInt) {
		if (this.keyboardType != paramInt) {
			if (paramInt == 0) {
				get_keybd_type();
			} else
				this.keyboardType = paramInt;
			this.m_keyprocessor = null;
		}
	}

	public void setHostKeyboardType(int paramInt) {
		if (this.hostKeyboardType != paramInt) {
			this.hostKeyboardType = paramInt;
			this.m_keyprocessor = null;
		}
	}

	public boolean OnkeyTyped(KeyEvent paramKeyEvent) {
		int i = 0;
		int j = paramKeyEvent.getKeyChar();

		switch (this.keyboardType) {
		case 1034:
			if (paramKeyEvent.getKeyLocation() != 4) {
				i = getKeyboardKeycode(this.Spanish_Map, j, 1034);
			}
			if (paramKeyEvent.getModifiersEx() == 8192) {
				i = getKeyboardKeycode(this.Spanish_Alt_gr_linuxMap, j, 1034);
				OnSendALTGR_Keyevent(i);
			} else {
				OnSend_Keyevent(i);
				return true;
			}

			break;
		case 1036:
			if (paramKeyEvent.getModifiers() == 1) {
				SHIFT_FLAG = true;
			}
			if (System.getProperty("os.name").equals("Linux")) {
				if (paramKeyEvent.getKeyLocation() != 4)
					i = getKeyboardKeycode(this.French_linuxMap, j, 1036);
				if ((DEAD_FLAG) && (i < 0)) {
					DEAD_FLAG = false;
				}
			}
			if (paramKeyEvent.getKeyLocation() != 4) {
				i = getKeyboardKeycode(this.French_WinMap, j, 1036);
			}
			if (paramKeyEvent.getModifiersEx() == 8192) {
				i = getKeyboardKeycode(this.French_Alt_gr_linuxMap, j, 1036);
				OnSendALTGR_Keyevent(i);

			} else if (i > 0) {
				OnSend_Keyevent(i);
				return true;
			}

			break;
		case 2060:
			if (paramKeyEvent.getModifiers() == 1) {
				SHIFT_FLAG = true;
			}
			if (paramKeyEvent.getKeyLocation() != 4) {
				i = getKeyboardKeycode(this.French_Belgium_Map, j, 1036);
			}
			if (paramKeyEvent.getModifiersEx() == 8192) {
				i = getKeyboardKeycode(this.French_Alt_gr_linuxMap, j, 1036);
				OnSendALTGR_Keyevent(i);

			} else if (i > 0) {
				OnSend_Keyevent(i);
				return true;
			}

			break;
		case 2055:
			if (paramKeyEvent.getModifiers() == 1) {
				SHIFT_FLAG = true;
			}
			if (paramKeyEvent.getKeyLocation() != 4) {
				i = getKeyboardKeycode(this.German_Swiss_Map, j, 2055);
			}
			if (paramKeyEvent.getModifiersEx() == 8192) {
				i = getKeyboardKeycode(this.French_Alt_gr_linuxMap, j, 1036);
				OnSendALTGR_Keyevent(i);

			} else if (i > 0) {
				OnSend_Keyevent(i);
				return true;
			}

			break;
		case 1031:
			if ((j == 223) || (j == 63)) {
				OnSend_Keyevent(47);
				return true;
			}

			if (paramKeyEvent.getModifiers() == 1) {
				SHIFT_FLAG = true;
			}
			if (paramKeyEvent.getKeyLocation() != 4) {
				i = getKeyboardKeycode(this.German_Map, j, 1031);
				if ((DEAD_FLAG) && (i < 0)) {
					DEAD_FLAG = false;
				}
			}
			if (paramKeyEvent.getModifiersEx() == 8192) {
				i = getKeyboardKeycode(this.German_Map_Alt_gr_linuxMap, j, 1031);
				OnSendALTGR_Keyevent(i);

			} else if (i > 0) {
				OnSend_Keyevent(i);
				return true;
			}

			break;
		}

		return false;
	}

	private void OnSendALTGR_Keyevent(int paramInt) {
		KVMClient localKVMClient = JViewerApp.getInstance().getKVMClient();
		USBKeyboardRep localUSBKeyboardRep = JViewerApp.getInstance().getM_USBKeyRep();
		localUSBKeyboardRep.set(17, 2, false);
		localKVMClient.sendKMMessage(localUSBKeyboardRep);
		localUSBKeyboardRep.set(18, 3, false);
		localKVMClient.sendKMMessage(localUSBKeyboardRep);
		localUSBKeyboardRep.set(18, 3, true);
		localKVMClient.sendKMMessage(localUSBKeyboardRep);
		localUSBKeyboardRep.set(paramInt, 1, true);
		localKVMClient.sendKMMessage(localUSBKeyboardRep);
		localUSBKeyboardRep.set(paramInt, 1, false);
		localKVMClient.sendKMMessage(localUSBKeyboardRep);
		localUSBKeyboardRep.set(18, 3, false);
		localKVMClient.sendKMMessage(localUSBKeyboardRep);
	}

	private void OnSend_Keyevent(int paramInt) {
		KVMClient localKVMClient = JViewerApp.getInstance().getKVMClient();
		USBKeyboardRep localUSBKeyboardRep = JViewerApp.getInstance().getM_USBKeyRep();
		localUSBKeyboardRep.set(paramInt, 1, true);
		localKVMClient.sendKMMessage(localUSBKeyboardRep);
		localUSBKeyboardRep.set(paramInt, 1, false);
		localKVMClient.sendKMMessage(localUSBKeyboardRep);
	}

	private void OnSendShiftGrave_Keyevent(int paramInt1, int paramInt2) {
		KVMClient localKVMClient = JViewerApp.getInstance().getKVMClient();
		USBKeyboardRep localUSBKeyboardRep = JViewerApp.getInstance().getM_USBKeyRep();
		localUSBKeyboardRep.set(16, paramInt2, true);
		localKVMClient.sendKMMessage(localUSBKeyboardRep);
		localUSBKeyboardRep.set(paramInt1, 1, true);
		localKVMClient.sendKMMessage(localUSBKeyboardRep);
		localUSBKeyboardRep.set(16, paramInt2, false);
		localKVMClient.sendKMMessage(localUSBKeyboardRep);
		localUSBKeyboardRep.set(paramInt1, 1, false);
		localKVMClient.sendKMMessage(localUSBKeyboardRep);
	}

	public boolean OnkeyPressed(KeyEvent paramKeyEvent) {
//		KVMClient localKVMClient = JViewerApp.getInstance().getKVMClient();
//		USBKeyboardRep localUSBKeyboardRep = JViewerApp.getInstance().getM_USBKeyRep();
		switch (this.keyboardType) {
		case 1031:
		case 1034:
		case 1036:
			int i = paramKeyEvent.getModifiersEx();

			if (i == 8192) {
				return true;
			}
			if (i == 640) {
				return true;
			}
			if (this.keyboardType == 1031) {
				if (paramKeyEvent.getKeyChar() == '~') {
					OnSend_Keyevent(61);
					return true;
				}

				if (paramKeyEvent.getKeyCode() == 521) {
					PLUS_FLAG = true;
				}
			}
			break;
		default:
			return false;
		}
		return false;
	}

	public boolean OnkeyReleased(KeyEvent paramKeyEvent) {
//		KVMClient localKVMClient = JViewerApp.getInstance().getKVMClient();
//		USBKeyboardRep localUSBKeyboardRep = JViewerApp.getInstance().getM_USBKeyRep();

		if (((paramKeyEvent.getModifiersEx() & 0x200) == 512) && (this.keyboardType == 1033)
				&& (!JViewerApp.getInstance().isFullKeyboardEnabled())) {
			return true;
		}

		int i = paramKeyEvent.getKeyCode();

		switch (this.keyboardType) {
		case 1031:
			if (System.getProperty("os.name").equals("Linux")) {
				if ((i == 130) && (!SHIFT_FLAG)) {
					OnSend_Keyevent(192);
					DEAD_FLAG = true;
					return true;
				}

				if ((i == 521) && (!PLUS_FLAG) && (paramKeyEvent.getModifiers() == 32)) {
					OnSendALTGR_Keyevent(521);
					PLUS_FLAG = false;
					return true;
				}

				if ((i == 129) && (!SHIFT_FLAG)) {
					OnSend_Keyevent(61);
					DEAD_FLAG = true;
					return true;
				}

				if ((i == 129) && (SHIFT_FLAG)) {
					OnSendShiftGrave_Keyevent(61, SHIFT_KEY_POSITION);
					DEAD_FLAG = true;
					return true;
				}

				if (DEAD_FLAG) {
					OnSend_Keyevent(i);
					DEAD_FLAG = false;
					SHIFT_FLAG = false;
					return true;
				}

				if (i == 16) {
					SHIFT_FLAG = true;
					SHIFT_KEY_POSITION = paramKeyEvent.getKeyLocation();
					DEAD_FLAG = false;
				} else {
					SHIFT_FLAG = false;
					DEAD_FLAG = false;
					SHIFT_KEY_POSITION = 0;
				}

				PLUS_FLAG = false;
			}
			break;
		case 1036:
			if (System.getProperty("os.name").equals("Linux")) {
				if ((i == 130) && (!SHIFT_FLAG)) {
					OnSend_Keyevent(91);
					DEAD_FLAG = true;
					return true;
				}

				if ((i == 130) && (SHIFT_FLAG)) {
					OnSendShiftGrave_Keyevent(91, SHIFT_KEY_POSITION);
					DEAD_FLAG = true;
					return true;
				}

				if (DEAD_FLAG) {
					OnSend_Keyevent(i);
					DEAD_FLAG = false;
					SHIFT_FLAG = false;
					SHIFT_KEY_POSITION = 0;
					return true;
				}

				if (i == 16) {
					SHIFT_FLAG = true;
					SHIFT_KEY_POSITION = paramKeyEvent.getKeyLocation();
					DEAD_FLAG = false;
				} else {
					SHIFT_FLAG = false;
					SHIFT_KEY_POSITION = 0;
					DEAD_FLAG = false;
				}
			}
			break;
		case 1034:
			if (System.getProperty("os.name").equals("Linux")) {
				if ((i == 129) && (!SHIFT_FLAG) && (!ALT_GR_FLAG)) {
					OnSend_Keyevent(129);
					if (!DEAD_FLAG) {
						DEAD_FLAG = true;
					} else
						DEAD_FLAG = false;
					return true;
				}

				if ((i == 128) && (!SHIFT_FLAG) && (!ALT_GR_FLAG)) {
					OnSend_Keyevent(128);
					if (!DEAD_FLAG) {
						DEAD_FLAG = true;
					} else
						DEAD_FLAG = false;
					return true;
				}

				if ((i == 129) && (SHIFT_FLAG) && (!ALT_GR_FLAG)) {
					OnSendShiftGrave_Keyevent(129, SHIFT_KEY_POSITION);
					if (!DEAD_FLAG) {
						DEAD_FLAG = true;
					} else
						DEAD_FLAG = false;
					return true;
				}

				if ((i == 128) && (SHIFT_FLAG) && (!ALT_GR_FLAG)) {
					OnSendShiftGrave_Keyevent(128, SHIFT_KEY_POSITION);
					if (!DEAD_FLAG) {
						DEAD_FLAG = true;
					} else
						DEAD_FLAG = false;
					return true;
				}

				if ((DEAD_FLAG) && (!ALT_GR_FLAG)) {
					OnSend_Keyevent(i);
					DEAD_FLAG = false;
					SHIFT_FLAG = false;
					SHIFT_KEY_POSITION = 0;
					return true;
				}

				if (i == 16) {
					SHIFT_FLAG = true;
					SHIFT_KEY_POSITION = paramKeyEvent.getKeyLocation();
					DEAD_FLAG = false;
					ALT_GR_FLAG = false;
				} else {
					SHIFT_FLAG = false;
					SHIFT_KEY_POSITION = 0;
					DEAD_FLAG = false;
					ALT_GR_FLAG = false;
				}
			}
			break;
		}
		return false;
	}

	public KeyProcessor ongetKeyprocessor() {
		if (this.m_keyprocessor == null) {
			if (JViewerApp.getInstance().getJVMenu().getMenuSelected("Auto detect").booleanValue()) {
				this.m_keyprocessor = selectKeyProcessor(this.keyboardType);
			} else
				this.m_keyprocessor = selectKeyProcessor(this.hostKeyboardType);
		}
		return this.m_keyprocessor;
	}

	private KeyProcessor selectKeyProcessor(int paramInt) {
		Object localObject;
		switch (paramInt) {
		case 1041:
			localObject = new USBKeyProcessorJapaneseHost();
			JViewerApp.getInstance().getJVMenu().notifyMenuStateSelected("JP", true);
			break;
		case 1031:
			localObject = new USBKeyProcessorQWERTZ(4);
			JViewerApp.getInstance().getJVMenu().notifyMenuStateSelected("DE", true);
			break;
		case 1036:
			localObject = new USBKeyProcessorAZERTY(3);
			JViewerApp.getInstance().getJVMenu().notifyMenuStateSelected("FR", true);
			break;
		case 1034:
			localObject = new USBKeyProcessorQWERTY(2);
			JViewerApp.getInstance().getJVMenu().notifyMenuStateSelected("ES", true);
			break;
		case 2057:
			localObject = new USBKeyProcessorQWERTY(1);
			JViewerApp.getInstance().getJVMenu().notifyMenuStateSelected("GB", true);
			break;
		case 2055:
			localObject = new USBKeyProcessorQWERTZ(8);
			JViewerApp.getInstance().getJVMenu().notifyMenuStateSelected("DE-CH", true);
			break;
		case 2060:
			localObject = new USBKeyProcessorAZERTY(13);
			JViewerApp.getInstance().getJVMenu().notifyMenuStateSelected("FR-BE", true);
			break;
		case 1040:
			localObject = new USBKeyProcessorQWERTY(5);
			JViewerApp.getInstance().getJVMenu().notifyMenuStateSelected("IT", true);
			break;
		case 1030:
			localObject = new USBKeyProcessorQWERTY(6);
			JViewerApp.getInstance().getJVMenu().notifyMenuStateSelected("DA", true);
			break;
		case 1035:
			localObject = new USBKeyProcessorQWERTY(7);
			JViewerApp.getInstance().getJVMenu().notifyMenuStateSelected("FI", true);
			break;
		case 1044:
			localObject = new USBKeyProcessorQWERTY(9);
			JViewerApp.getInstance().getJVMenu().notifyMenuStateSelected("NO", true);
			break;
		case 2070:
			localObject = new USBKeyProcessorQWERTY(10);
			JViewerApp.getInstance().getJVMenu().notifyMenuStateSelected("PT", true);
			break;
		case 1053:
			localObject = new USBKeyProcessorQWERTY(11);
			JViewerApp.getInstance().getJVMenu().notifyMenuStateSelected("SV", true);
			break;
		case 1043:
			localObject = new USBKeyProcessorQWERTY(21);
			JViewerApp.getInstance().getJVMenu().notifyMenuStateSelected("NL-NL", true);
			break;
		case 2067:
			localObject = new USBKeyProcessorAZERTY(14);
			JViewerApp.getInstance().getJVMenu().notifyMenuStateSelected("NL-BE", true);
			break;
		case 66591:
			localObject = new USBKeyProcessorTurkishF();
			JViewerApp.getInstance().getJVMenu().notifyMenuStateSelected("TR_F", true);
			break;
		case 1055:
			localObject = new USBKeyProcessorQWERTY(18);
			JViewerApp.getInstance().getJVMenu().notifyMenuStateSelected("TR_Q", true);
			break;
		default:
			if (JViewerApp.getInstance().getJVMenu().getMenuSelected("Auto detect").booleanValue()) {
				localObject = new USBKeyProcessorEnglish();
			} else
				localObject = new USBKeyProcessorQWERTY(0);
			JViewerApp.getInstance().getJVMenu().notifyMenuStateSelected("US", true);
		}
		return (KeyProcessor) localObject;
	}

	public void initKeyProcessor() {
		this.m_keyprocessor = null;
	}

	private int getKeyboardKeycode(HashMap<Integer, Integer> paramHashMap, int paramInt1, int paramInt2) {
		try {
			return ((Integer) paramHashMap.get(Integer.valueOf(paramInt1))).intValue();
		} catch (Exception localException) {
			switch (paramInt2) {
			case 1036:
				Debug.out.println("Exception in KBD_TYPE_FRENCH" + localException);
				break;
			case 1034:
				Debug.out.println("Exception in KBD_TYPE_SPANISH" + localException);
				break;
			case 1031:
				Debug.out.println("Exception in KBD_TYPE_GERMAN" + localException);
				break;
			case 1033:
				Debug.out.println("Exception in KBD_TYPE_ENGLISH" + localException);
				break;
			case 1041:
				Debug.out.println("Exception in KBD_TYPE_JAPANESE" + localException);
			}
		}
		return -1;
	}
}
